﻿//===============================================================================
// Microsoft Innovation Centre - Western Europe
// Copyright (c) 2008 Microsoft Corporation. All rights reserved.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;
using System.Collections.Generic;
using Microsoft.WVB.Framework.Entities;

namespace Microsoft.WVB.Framework
{
    // TODO: REWIRTE with Generics ...
    public delegate void CreateProfileEventHandler<T>(AcquireCompletedEventArgs<T> e) where T: class;
    public delegate void GetProfileEventHandler<T>(AcquireCompletedEventArgs<T> e) where T: class;

    public abstract class ProfileProvider<T> : IProfileProvider<T> where T: class, IProfileInfo
    {
        protected string serviceRoot { get; private set; }
        public ProfileProvider(string path)
        {
            // TODO: Should check if the path is a valid Uri with Http/Https scheme
            serviceRoot = path;
        }

        public event GetProfileEventHandler<T> GetProfileCompleted;
        public abstract void GetProfileAsync(string username, object userData);
        public void GetProfileAsync(string username) { GetProfileAsync(username, null); }
        protected virtual void OnGetProfileCompleted(AcquireCompletedEventArgs<T> e)
        {
            if (GetProfileCompleted != null)
            {
                GetProfileCompleted(e);
            }
        }

        public event CreateProfileEventHandler<T> CreateProfileCompleted;
        public abstract void CreateProfileAsync(T profile, object userData);
        public void CreateProfileAsync(T profile) { CreateProfileAsync(profile, null); }
        protected virtual void OnCreateProfileCompleted(AcquireCompletedEventArgs<T> e)
        {
            if (CreateProfileCompleted != null)
            {
                CreateProfileCompleted(e);
            }
        }

        public event EventHandler<NotifyActionCompletedEventArgs> DeleteProfileCompleted;
        public abstract void DeleteProfileAsync(string username, object userData);
        public void DeleteProfileAsync(string username) { DeleteProfileAsync(username, null); }
        public void DeleteProfileAsync(T profile, object userData)
        {
            DeleteProfileAsync(profile.Username, userData);
        }
        public void DeleteProfileAsync(T profile) { DeleteProfileAsync(profile, null); }
        protected virtual void OnDeleteProfileCompleted(NotifyActionCompletedEventArgs e)
        {
            if (DeleteProfileCompleted != null)
            {
                DeleteProfileCompleted(this, e);
            }
        }

        public event EventHandler<NotifyActionCompletedEventArgs> UpdateProfileCompleted;
        public abstract void UpdateProfileAsync(T profile, object userData);
        public void UpdateProfileAsync(T profile) { UpdateProfileAsync(profile, null); }
        protected virtual void OnUpdateProfileCompleted(NotifyActionCompletedEventArgs e)
        {
            if (UpdateProfileCompleted != null)
            {
                UpdateProfileCompleted(this, e);
            }
        }

        public abstract void CancelAsynch();
    }
}
